<template>
    <div style="height: 100%; width: 100%; position: relative" ref="maindev">
        <div class="pagetop" :style="pagetopstyle">
            <div style="width: 100%">
                <table>
                    <tr>
                        <td>接收日期</td>
                        <td>
                            <el-date-picker v-model="datetime1" type="datetime" placeholder="选择日期" value-format="yyyy-MM-dd HH:mm" style="width: 175px" :clearable="false"> </el-date-picker>
                            -
                            <el-date-picker v-model="datetime2" type="datetime" placeholder="选择日期" value-format="yyyy-MM-dd HH:mm" style="width: 175px" :clearable="false"> </el-date-picker>
                        </td>
                        <td>病人类型</td>
                        <td>
                            <el-select v-model="pattype" @dblclick.native="popMultipleChk(pattype, 'pattype', pattypeOption, '病人类型选择')" filterable clearable style="width: 140px" @change="haveChange(1)">
                                <el-option v-for="(item, index) in pattypeOption" :value="item.data" :label="item.display" :key="index"></el-option>
                            </el-select>
                        </td>
                        <td>接收状态</td>
                        <td>
                            <el-select clearable v-model="statflag" style="width: 100%" @change="haveChange(2)">
                                <el-option value="1" label="仅已接收的标本"></el-option>
                                <el-option value="2" label="包含门诊未接收的标本"></el-option>
                                <el-option value="3" label="包含除住院外已采样的标本"></el-option>
                            </el-select>
                        </td>
                        <td>签收状态</td>
                        <td>
                            <el-select v-model="workgroupreeieveflag" style="width: 100%" @change="haveChange(3)">
                                <el-option value="1" label="全部"></el-option>
                                <el-option value="2" label="剔除工作组签收过的标本"></el-option>
                                <el-option value="3" label="仅查询工作组签收过的标本"></el-option>
                            </el-select>
                        </td>
                        <td>上机状态</td>
                        <td>
                            <el-select clearable v-model="reqflag" style="width: 100%" @change="haveChange(4)">
                                <el-option value="1" label="查询申请单是否上机过"></el-option>
                                <el-option value="2" label="按申请项目上机状况查询"></el-option>
                                <el-option value="3" label="查询报告项目未全部上机"></el-option>
                            </el-select>
                        </td>
                    </tr>
                    <tr>
                        <td>检验组</td>
                        <td>
                            <el-select v-model="labgroup" @dblclick.native="popMultipleChk(labgroup, 'labgroup', labgroupOption, '检验组选择')" filterable clearable style="width: 100%" @change="haveChange(5)">
                                <el-option v-for="(item, index) in labgroupOption" :value="item.data" :label="item.display" :key="index"></el-option>
                            </el-select>
                            <!-- <rm-ddl-common datatype="labgroup" dataname="检验工作组" v-model="labgroup" width="100%"></rm-ddl-common> -->
                        </td>
                        <td>分单类别</td>
                        <td>
                            <el-select v-model="reqgroupid" @dblclick.native="popMultipleChk(reqgroupid, 'reqgroupid', reqgroupOption, '分单类别选择')" filterable clearable style="width: 140px" @change="haveChange(6)">
                                <el-option v-for="(item, index) in reqgroupOption" :value="item.data" :label="item.display" :key="index"></el-option>
                            </el-select>
                        </td>
                        <td colspan="6" align="left">
                            <el-checkbox v-model="emerflag" false-label="0" true-label="1" @change="haveChange(17)">仅显示急诊标本</el-checkbox>
                            <el-checkbox v-model="sendflag" false-label="0" true-label="1" @change="haveChange(18)">仅显示已送达标本</el-checkbox>
                            <el-checkbox v-model="islisreqbarcode" false-label="0" true-label="1" @change="haveChange(19)">剔除实验室手工添条码</el-checkbox>
                            <el-checkbox v-model="onlyreportvsreqdetail" false-label="0" true-label="1" @change="haveChange(20)">仅显示申请项目部分上机的</el-checkbox>
                            <el-checkbox v-model="isrejectonlinebarcode" false-label="0" true-label="1" @change="haveChange(21)">剔除已上机状态条码</el-checkbox>
                        </td>
                    </tr>
                    <tr v-show="showmoreflag">
                        <td>执行科室</td>
                        <td>
                            <rm-ddl-common datatype="dept" dataname="执行科室" v-model="performdept" width="100%" @change="performdeptChange"></rm-ddl-common>
                        </td>
                        <td @click="showhelp('grouplabdept')">检验科室<span style="color:blue" class="el-icon-info"></span></td>
                        <td>
                            <rm-ddl-common datatype="labdept" dataname="检验科室" v-model="labdeptcode" width="140px" @change="labdeptChange"></rm-ddl-common>
                        </td>
                        <td>申请项目</td>
                        <td>
                            <el-select v-model="reqitem" @dblclick.native="popMultipleChk(reqitem, 'reqitem', reqitemOption, '申请项目选择')" style="width: 100%" filterable clearable @change="haveChange(9)">
                                <el-option v-for="(item, index) in reqitemOption" :key="index" :value="item.data" :label="item.display"> </el-option>
                            </el-select>
                        </td>
                        <td>报告单元</td>
                        <td>
                            <el-select v-model="rptunitid" @dblclick.native="popMultipleChk(rptunitid, 'rptunitid', rptunitOption, '请选择报告单元')" filterable clearable style="width: 100%" @change="haveChange(10)">
                                <el-option v-for="(item, index) in rptunitOption" :key="index" :value="item.data" :label="item.display"></el-option>
                            </el-select>
                        </td>
                        <td>标本类型</td>
                        <td>
                            <rm-ddl-common datatype="specimen" dataname="标本类型" v-model="specimencode" width="100%" @change="specimenChange"></rm-ddl-common>
                        </td>
                    </tr>
                    <tr v-show="showmoreflag">
                        <td>签收人</td>
                        <td>
                            <rm-ddl-common datatype="userinfo" dataname="签收人" v-model="recieveuser" width="100%" @change="recieveuserChange"></rm-ddl-common>
                        </td>
                        <td>申请项目组合</td>
                        <td>
                            <rm-ddl-common datatype="reqitemcomb" dataname="申请项目组合" v-model="reqcombid" width="140px" @change="reqcombChange"></rm-ddl-common>
                        </td>
                        <td>签收工作组</td>
                        <td>
                            <rm-ddl-common datatype="labgroup" dataname="工作组" v-model="recgroupid" width="100%" @change="recgroupChange"></rm-ddl-common>
                        </td>
                        <td>病人医院</td>
                        <td>
                            <rm-ddl-common datatype="hospital" dataname="检验医院" v-model="labhospital" width="100%" @change="labhospChange"></rm-ddl-common>
                        </td>
                        <td>条码号</td>
                        <td>
                            <el-input v-model="txtbarcode" style="width: 100%" ref="reftxtbarcode" clearable @change="haveChange(16)"></el-input>
                        </td>
                    </tr>
                    <tr v-show="showmoreflag">
                        <td>分单类别组合</td>
                        <td>
                            <rm-ddl-common datatype="groupcombid" dataname="分单类别组合" v-model="groupcombid" width="100%" @change="groupcombChange"></rm-ddl-common>
                        </td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                </table>
                <div style="width: 100%; text-align: right; padding-bottom: 5px">
                    <el-link :underline="false" @click="OpenMoreSel">{{ showmoreflag ? "收起▲" : "展开▼" }}</el-link>
                    <el-button type="primary" icon="el-icon-search" v-has="'PINQUERY'" @click="QueryData()">查询</el-button>
                    <el-button @click="exportData" icon="el-icon-upload2">导出</el-button>
                    <el-button @click="setExportColumn">导出列设置</el-button>
                </div>
            </div>
        </div>
        <div :style="pagecenter">
            <rm-layout-right :fixsize="520" :splitwidth="5" :minfixsize="200" :maxflxsize="2000">
                <div :style="middle_center">
                    <vxe-table :data.sync="tableData" :loading="loading" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border :height="reportheight" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="maintable" resizable show-overflow size="mini" show-header-overflow :optimization="{ animat: false }" @current-change="DataSelect" header-align="center">
                        <vxe-table-column field="barcode" title="条码号" width="80" show-overflow align="center" sortable></vxe-table-column>
                        <vxe-table-column field="labgroupname" title="检验组" width="80" show-overflow align="center" sortable></vxe-table-column>
                        <vxe-table-column field="pat_typename" title="病人来源" width="80" show-overflow align="center" sortable></vxe-table-column>
                        <vxe-table-column field="req_groupna" title="分单类别" width="80" show-overflow align="center" sortable>
                            <template v-slot="{ row }">
                                <div v-bind:style="{ background: $pub.ColorChange(row.tube_color) }">{{ row.req_groupna }}</div>
                            </template>
                        </vxe-table-column>
                        <vxe-table-column field="create_dt" align="center" title="创建时间" width="140" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="recieve_dt" align="center" title="接收时间" width="140" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="recieve_username" align="center" title="接收人" width="60" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="create_username" align="center" title="创建人" width="60" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="emer_flag" title="加急" width="40px" align="center" sortable>
                            <template v-slot="{ row }">
                                <span style="color: red" v-if="row.emer_flag == '1'">急</span>
                                <span v-else></span>
                            </template>
                        </vxe-table-column>
                        <vxe-table-column field="sample_items" align="center" title="申请项目（简称，部分）" width="160px" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="req_deptname" align="center" title="申请科室" width="100" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="perform_deptname" align="center" title="执行科室" width="100" show-overflow sortable></vxe-table-column>

                        <vxe-table-column field="pat_name" title="姓名" width="60" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="pat_no" align="center" title="病历号" width="80" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="req_statname" title="状态" width="90" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="req_docname" align="center" title="申请医生" width="50" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="req_bedno" align="center" title="床号" width="80" show-overflow></vxe-table-column>
                        <vxe-table-column field="specimen_name" title="标本类型" width="100" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="pat_sexname" title="性别" width="40px" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="pat_agestr" title="年龄" width="60px" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="print_dt" title="打印/执行时间" width="140px" show-overflow></vxe-table-column>
                        <vxe-table-column field="print_username" align="center" title="打印/执行人" width="140" show-overflow></vxe-table-column>
                        <vxe-table-column field="sampled_dt" align="center" title="采样时间" width="140" show-overflow></vxe-table-column>
                        <vxe-table-column field="sampled_username" title="采样人" width="110" show-overflow></vxe-table-column>
                        <vxe-table-column field="req_dt" title="申请时间" width="140" show-overflow></vxe-table-column>
                        <vxe-table-column field="prereport_dt" align="center" title="预出报告时间" width="140" show-overflow></vxe-table-column>
                        <vxe-table-column field="send_dt" align="center" title="送出时间" width="140" show-overflow></vxe-table-column>
                        <vxe-table-column field="send_username" align="center" title="送出人" width="140" show-overflow></vxe-table-column>
                        <vxe-table-column field="charge_dt" title="计价时间" width="120" show-overflow></vxe-table-column>
                        <vxe-table-column field="charge_username" align="center" title="计价人" width="140" show-overflow></vxe-table-column>
                        <vxe-table-column field="amount" align="center" title="实收金额" width="60px" show-overflow></vxe-table-column>
                        <vxe-table-column field="charge_flag" align="center" title="计价标志" width="70" show-overflow></vxe-table-column>
                        <vxe-table-column field="req_comm" title="医生备注" width="130" show-overflow></vxe-table-column>
                        <vxe-table-column field="pat_birth" title="生日" width="150" show-overflow></vxe-table-column>
                        <vxe-table-column field="charge_typename" title="费别代码" width="100" show-overflow></vxe-table-column>
                        <vxe-table-column field="req_wardname" align="center" title="病区" width="100" show-overflow></vxe-table-column>
                        <vxe-table-column field="original_reqno" title="原始申请单号" width="150" show-overflow></vxe-table-column>
                        <vxe-table-column field="reject_dt" align="center" title="剔回时间" width="140" show-overflow></vxe-table-column>
                        <vxe-table-column field="reject_username" align="center" title="剔回人" width="70" show-overflow></vxe-table-column>
                        <vxe-table-column field="reject_reason" align="center" title="剔回原因" width="140" show-overflow></vxe-table-column>
                        <vxe-table-column field="reject_count" align="center" title="剔回次数" width="90" show-overflow></vxe-table-column>
                        <vxe-table-column field="reqtype" align="center" title="申请单类别" width="140" show-overflow></vxe-table-column>
                        <vxe-table-column field="reportid" title="报告ID" width="160" show-overflow></vxe-table-column>
                        <vxe-table-column field="cp_itemnames" title="申请项目（未上机）" width="180" show-overflow></vxe-table-column>
                        <vxe-table-column field="report_username" align="center" title="检验者" width="140" show-overflow></vxe-table-column>
                        <vxe-table-column field="report_comm" title="报告备注" width="100" show-overflow></vxe-table-column>
                    </vxe-table>
                </div>
                <template v-slot:fix>
                    <div class="middle-right">
                        <div class="right-inser">
                            <div class="middle-tab-top">
                                <vxe-table :data.sync="tableDatareq" :loading="loadingreq" height="auto" resizable header-align="center" show-overflow="tooltip" :row-class-name="ReqItemRowName" show-header-overflow="tooltip" size="mini" border stripe column-width="100px" ref="tablereq">
                                    <vxe-table-column field="req_itemname" title="项目名称" width="160px"></vxe-table-column>
                                    <vxe-table-column field="item_price" title="实际价格" width="100px" align="right" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="qty" title="数量" width="80px" align="right" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="amount" title="金额" width="100px" text-align="center" align="right" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="seq" title="序号" width="60px"></vxe-table-column>
                                    <vxe-table-column field="base_price" title="基础价格" width="80px"></vxe-table-column>
                                    <vxe-table-column field="req_itemcode" title="项目代码" width="100px"></vxe-table-column>
                                    <vxe-table-column field="his_itemcode" title="HIS项目代码" width="100px"></vxe-table-column>
                                    <vxe-table-column field="his_recordid" title="HIS记录号" width="100px"></vxe-table-column>
                                    <vxe-table-column field="reportid" title="报告ID" width="100px"></vxe-table-column>
                                    <template v-slot:fix>
                                        <div class="table-bottom">
                                            <span>
                                                <el-checkbox v-model="hideinstalled" true-label="1" false-label="0" @change="hideinstalledChange">隐藏已上机</el-checkbox>
                                            </span>
                                        </div>
                                    </template>
                                </vxe-table>
                            </div>
                            <div class="middle-tab-bottom">
                                <vxe-table :data.sync="tableDatalog" :loading="loadinglog" :height="resultheight" highlight-current-row highlight-hover-row resizable header-align="center" show-overflow="tooltip" show-header-overflow="tooltip" size="mini" border stripe column-width="100px" ref="tablelog">
                                    <vxe-table-column field="log_date" title="操作日期" width="120px" align="center"></vxe-table-column>
                                    <vxe-table-column field="transname" title="操作类型" width="80px" align="center"></vxe-table-column>
                                    <vxe-table-column field="log_content" title="操作内容" width="200px"></vxe-table-column>
                                    <vxe-table-column field="username" title="操作者" width="100px" align="center"></vxe-table-column>
                                    <vxe-table-column field="ref_user" title="相关人" width="100px"></vxe-table-column>
                                    <vxe-table-column field="labgroupid" title="工作组" width="100px"></vxe-table-column>
                                    <vxe-table-column field="computer_name" title="操作时机器名" width="100px">
                                        <template v-slot="{ row }">
                                            <span style="color:blue;">{{row.computer_name}}</span>
                                            <i class="el-icon-refresh" @click="repalceComputerName(row)"></i>
                                        </template>
                                    </vxe-table-column>
                                    <vxe-table-column field="mac_address" title="操作时机器MAC" width="100px"></vxe-table-column>
                                    <vxe-table-column field="syncflag" title="同步HIS标志" width="100px"></vxe-table-column>
                                    <vxe-table-column field="synctime" title="同步时间" width="100px"></vxe-table-column>
                                    <vxe-table-column field="syncerrtext" title="同步失败信息" width="100px"></vxe-table-column>
                                </vxe-table>
                            </div>
                        </div>
                    </div>
                </template>
            </rm-layout-right>
        </div>

        <el-dialog width="900px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="multichktitle" :visible.sync="dialogMultipleVisible" :destroy-on-close="true">
            <rm-SqlMultiple :leftOption="option1" :rightOption="option2" :name="fieldname" @change="closedialog"></rm-SqlMultiple>
        </el-dialog>

        <el-dialog title="导出列选择" :visible.sync="chooseColumndialogVisible" width="380px" v-el-drag-dialog :close-on-click-modal="false">
            <rm-excolsetting :excolPro="excolPro" :allTableCol="allTableCol" @change="saveExportColumn"></rm-excolsetting>
        </el-dialog>
        <rm-excolsetting :excolPro="excolPro" :allTableCol="allTableCol" @change="saveExportColumn" ref="excolset" v-show="false"></rm-excolsetting>
    </div>
</template>

<script>
import XEUtils from "xe-utils"; //引入工具类
import RmExcolsetting from "@/components/rmcompents/rm_excolsetting.vue";
export default {
    name: "LIS240",
    components: { RmExcolsetting },
    data() {
        return {
            pagetopstyle: {
                // position: "absolute",
                height: "100px",
                width: "100%",
            },
            pagecenter: {
                position: "absolute",
                top: "105px",
                bottom: "0px",
                overflow: "auto",
                width: "100%",
                left: "0px",
            },
            middle_center: {
                position: "absolute",
                height: "100%",
                right: "0px",
                left: "0px",
                overflow: "auto",
            },
            datetime1: "",
            datetime2: "",
            pattype: "", //病人类型
            labgroup: "", //检验工作组
            groupcombid: "", //检验工作组合
            reqgroupid: "", //分单类别
            statflag: "1", //接收状态
            workgroupreeieveflag: "1", //签收状态
            reqflag: "1", //上机状态
            showmoreflag: false, //显示更多标志

            reportheight: "auto",

            reqitem: "",
            rptunitid: "",
            recieveuser: "",
            recgroupid: "", //签收人工作组
            reqcombid: "", //申请项目组合
            labdeptcode: "", //检验科室
            labhospital: "", //检验医院
            performdept: "", //执行科室
            specimencode: "",
            emerflag: "0",
            sendflag: "0",
            islisreqbarcode: "0",
            onlyreportvsreqdetail: "0",
            isrejectonlinebarcode: "0",
            hospOption: [],
            rptunitGroupOption: [],
            deptOption: [],
            labgroupOption: [],
            wardOption: [],
            pattypeOption: [],
            reqgroupOption: [],
            reqitemOption: [],
            chargetypeoption: [],
            rptunitOption: [],

            tableData: [],
            loading: false,
            tableDatareq: [],
            loadingreq: false,
            tableDatalog: [],
            loadinglog: false,
            selrow: {},

            //多选弹窗
            dialogMultipleVisible: false,
            option1: [],
            option2: [],
            fieldname: "",
            multichktitle: "",
            txtbarcode: "",
            //导出设置
            excolPro: "lis240",
            chooseColumndialogVisible: false,
            allTableCol: [],
            sampleData: [],
            resultheight: "auto",
            performdeptname: "",
            labdeptname: "",
            specimenname: "",
            recieveusername: "",
            reqcombname: "",
            groupcombname: "",
            recgroupname: "",
            labhospname: "",
            hideinstalled: "0",
        };
    },
    created() {
        this.initData();
        this.QueryOption();
    },
    updated() {},
    mounted() {
        let ishow = this.$tool.getLocalConfig("lis240smflag");
        if (ishow == "1") {
            this.OpenMoreSel();
        }
        this.$refs.excolset.colSettingToDB();
    },
    methods: {
        initData() {
            this.hideinstalled = localStorage.getItem("lis240hideinstalled");
            this.pattype = localStorage.getItem("lis240pattype");
            var lstatflag = localStorage.getItem("lis240statflag");
            if (lstatflag != "" && lstatflag != null) {
                this.statflag = lstatflag;
            }

            var lworkgroupreeieveflag = localStorage.getItem("lis240workgroupreeieveflag");
            if (lworkgroupreeieveflag != "" && lworkgroupreeieveflag != null) {
                this.workgroupreeieveflag = lworkgroupreeieveflag;
            }

            var lreqflag = localStorage.getItem("lis240reqflag");
            if (lreqflag != "" && lreqflag != null) {
                this.reqflag = lreqflag;
            }

            this.labgroup = localStorage.getItem("lis240labgroup");
            this.reqgroupid = localStorage.getItem("lis240reqgroupid");
            this.emerflag = localStorage.getItem("lis240emerflag");
            this.sendflag = localStorage.getItem("lis240sendflag");
            this.islisreqbarcode = localStorage.getItem("lis240islisreqbarcode");
            this.onlyreportvsreqdetail = localStorage.getItem("lis240onlyreportvsreqdetail");
            this.isrejectonlinebarcode = localStorage.getItem("lis240isrejectonlinebarcode");
            this.performdept = localStorage.getItem("lis240dept");
            this.performdeptname = localStorage.getItem("lis240deptname");
            this.labdeptcode = localStorage.getItem("lis240labdept");
            this.labdeptname = localStorage.getItem("lis240labdeptname");
            this.reqitem = localStorage.getItem("lis240reqitem");
            this.rptunitid = localStorage.getItem("lis240rptunitid");
            this.specimencode = localStorage.getItem("lis240specimencode");
            this.specimenname = localStorage.getItem("lis240specimenname");
            this.recieveuser = localStorage.getItem("lis240recieveuser");
            this.recieveusername = localStorage.getItem("lis240recieveusername");
            this.reqcombid = localStorage.getItem("lis240reqcombid");
            this.reqcombname = localStorage.getItem("lis240reqcombname");
            this.groupcombid = localStorage.getItem("lis240groupcombid");
            this.groupcombname = localStorage.getItem("lis240groupcombname");
            this.recgroupid = localStorage.getItem("lis240recgroupid");
            this.recgroupname = localStorage.getItem("lis240recgroupname");
            this.labhospital = localStorage.getItem("lis240labhospital");
            this.labhospname = localStorage.getItem("lis240labhospname");
        },
        OpenMoreSel() {
            let mainheight = this.$refs.maindev.offsetHeight;
            this.showmoreflag = !this.showmoreflag;
            let ishow = "0";
            if (this.showmoreflag) {
                this.pagetopstyle.height = "195px";
                this.pagecenter.top = "200px";
                this.reportheight = mainheight - 200;
                this.resultheight = this.reportheight - 205;
                ishow = "1";
            } else {
                this.pagetopstyle.height = "100px";
                this.pagecenter.top = "105px";
                this.reportheight = mainheight - 105;
                this.resultheight = this.reportheight - 205;
            }
            this.$tool.setLocalConfig("lis240smflag", ishow);
        },
        popMultipleChk(e, fieldname, option, title) {
            let temp = XEUtils.clone(option, true);
            this.option1 = [];
            this.option2 = [];
            if (e && e != "") {
                let k = e.split(",");
                k.forEach((item) => {
                    let ndata = temp.find((m) => m.data == item);
                    if (ndata != undefined && ndata != null) {
                        this.option2.push(ndata);
                    }
                });
                temp.forEach((item) => {
                    if (k.indexOf(item.data + "") < 0) {
                        this.option1.push(item);
                    }
                });
            } else {
                this.option1 = temp;
            }
            this.fieldname = fieldname;
            this.multichktitle = title;
            this.dialogMultipleVisible = true;
        },
        closedialog(value, name) {
            if (value != "close") {
                this[name] = value;
            }
            this.dialogMultipleVisible = false;
        },
        QueryOption() {
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS240",
                    method: "post",
                    data: {
                        action: "initOption",
                    },
                })
                .then((res) => {
                    this.pattypeOption = res.pattypeOption;
                    this.deptOption = res.deptOption;
                    this.hospOption = res.hospOption;
                    this.doctorOption = res.doctorOption;
                    this.rptunitOption = res.rptunitOption;
                    this.rptunitGroupOption = res.rptunitGroupOption;
                    this.reportcommOption = res.reportcommOption;
                    this.wardOption = res.wardOption;
                    this.labgroupOption = res.labgroupOption;
                    this.reqgroupOption = res.reqgroupOption;
                    this.reqitemOption = res.reqitemOption;
                    this.chargetypeoption = res.chargetypeoption;
                    this.datetime1 = res.datetime + " 00:00:00";
                    this.datetime2 = res.datetime + " 23:59:59";
                });
        },
        QueryData() {
            this.loading = true;
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS240",
                    method: "post",
                    data: {
                        action: "querybarcode",
                        datetime1: this.datetime1,
                        datetime2: this.datetime2,
                        reqgroup: this.reqgroupid,
                        rptunit: this.rptunitid,
                        reqitem: this.reqitem,
                        pattype: this.pattype,
                        recieveuser: this.recieveuser,
                        recgroupid: this.recgroupid,
                        reqcombid: this.reqcombid,
                        groupcombid: this.groupcombid,
                        labdeptcode: this.labdeptcode,
                        hospcode: this.labhospital,
                        peformedeptno: this.performdept,
                        specimencode: this.specimencode,
                        txtlabgoup: this.labgroup,
                        workgroupreeieveflag: this.workgroupreeieveflag,
                        statflag: this.statflag,
                        reqflag: this.reqflag,
                        emerflag: this.emerflag,
                        sendflag: this.sendflag,
                        onlyreportvsreqdetail: this.onlyreportvsreqdetail,
                        isrejectonlinebarcode: this.isrejectonlinebarcode,
                        islisreqbarcode: this.islisreqbarcode,
                        barcode: this.txtbarcode,
                    },
                })
                .then((res) => {
                    this.tableData = res.data;
                    this.sampleData = res.data;
                    if (res.data.length > 0) {
                        this.$nextTick(() => {
                            this.$refs.maintable.setCurrentRow(this.tableData[0]);
                            this.selrow = this.tableData[0];
                            this.QueryReq(this.tableData[0].barcode);
                            this.QueryLog(this.tableData[0].barcode);
                        });
                    } else {
                        this.tableData = [];
                        this.tableDatareq = [];
                        this.tableDatalog = [];
                        this.sampleData = [];
                    }
                    this.loading = false;
                });
        },

        QueryReq(barcode) {
            this.loadingreq = true;
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS240",
                    method: "post",
                    data: {
                        action: "queryreqitem",
                        barcode: barcode,
                    },
                })
                .then((res) => {
                    if(this.hideinstalled == "1") {
                        this.tableDatareq = [];
                        if(res.Data) {
                            res.Data.forEach((item)=>{
                                if (!item.reportid) this.tableDatareq.push(item);
                            });
                        }
                    } else {
                        this.tableDatareq = res.Data;
                    }
                    this.loadingreq = false;
                })
                .catch((err) => {
                    this.loadingreq = false;
                });
        },
        QueryLog(barcode) {
            this.loadinglog = true;
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS240",
                    method: "post",
                    data: {
                        action: "querylog",
                        barcode: barcode,
                    },
                })
                .then((res) => {
                    this.tableDatalog = res.Data;
                    this.loadinglog = false;
                })
                .catch((err) => {
                    this.loadinglog = false;
                });
        },
        DataSelect({ row, rowIndex }) {
            this.selrow = row;
            this.QueryReq(row.barcode);
            this.QueryLog(row.barcode);
        },

        saveExportColumn() {
            this.chooseColumndialogVisible = false;
        },
        setExportColumn() {
            let allColumnList = [];
            this.$refs.maintable.getTableColumn().tableColumn.forEach((element) => {
                if (element.property) {
                    allColumnList.push({
                        title: element.title,
                        property: element.property,
                    });
                }
            });
            this.allTableCol = allColumnList;
            this.chooseColumndialogVisible = true;
        },
        performdeptChange(code, name) {
            this.performdept = code;
            this.performdeptname = name;
            this.haveChange(7);
        },
        labdeptChange(code, name) {
            this.labdeptcode = code;
            this.labdeptname = name;
            this.haveChange(8);
        },
        specimenChange(code, name) {
            this.specimencode = code;
            this.specimenname = name;
            this.haveChange(11);
        },
        recieveuserChange(code, name) {
            (this.recieveuser = code), (this.recieveusername = name);
            this.haveChange(12);
        },
        reqcombChange(code, name) {
            this.reqcombid = code;
            this.reqcombname = name;
            this.haveChange(13);
        },
        recgroupChange(code, name) {
            this.recgroupid = code;
            this.recgroupname = name;
            this.haveChange(14);
        },
        labhospChange(code, name) {
            this.labhospital = code;
            this.labhospname = name;
            this.haveChange(15);
        },
        groupcombChange(code, name) {
            this.groupcombid = code;
            this.groupcombname = name;
            this.haveChange(16);
        },
        // 导出
        exportData() {
            var rightlocalStorage = JSON.parse(window.localStorage.getItem(this.excolPro + "exportCol"));
            var exportColumn = [];
            let column = this.$refs.maintable.getTableColumn().tableColumn;
            if (rightlocalStorage && rightlocalStorage.length > 0) {
                let columnArr = [];
                rightlocalStorage.forEach((item) => {
                    columnArr.push({
                        title: item.extitle ? item.extitle : item.title,
                        property: item.property,
                    });
                });
                exportColumn = columnArr;
            } else {
                exportColumn = this.$pub.InitColumn(column);
            }
            let data = this.getExportData(exportColumn);
            let filtertxt = this.getExportFilter();
            this.$pub.exportTableExcelWithData(data, exportColumn.length, "LIS240标本上机未签收查询.xlsx", filtertxt);
        },
        // 获取当前导出文件的所有查询条件
        getExportFilter() {
            let filtertxt = "接收日期:" + XEUtils.toDateString(this.datetime1, "yyyy-MM-dd HH:mm") + "至" + XEUtils.toDateString(this.datetime2, "yyyy-MM-dd HH:mm") + "; ";
            if (this.pattype) filtertxt += "病人类型:" + this.getOptionName(this.pattypeOption.filter((item) => ("," + this.pattype + ",").indexOf("," + item.data + ",") > -1)) + "; ";
            if (this.statflag) filtertxt += "接收状态:" + (this.statflag == "1" ? "仅已接收的标本" : this.statflag == "2" ? "包含门诊未接收的标本" : "包含除住院外已采样的标本") + "; ";
            if (this.workgroupreeieveflag) filtertxt += "签收状态:" + (this.workgroupreeieveflag == "2" ? "剔除工作组签收过的标本" : this.workgroupreeieveflag == "3" ? "仅查询工作组签收过的标本" : "全部") + "; ";
            if (this.reqflag) filtertxt += "上机状态:" + (this.reqflag == "1" ? "查询申请单是否上机过" : this.reqflag == "2" ? "按申请项目上机状况查询" : "查询报告项目未全部上机") + "; ";
            if (this.labgroup) filtertxt += "检验组:" + this.getOptionName(this.labgroupOption.filter((item) => ("," + this.labgroup + ",").indexOf("," + item.data + ",") > -1)) + "; ";
            if (this.reqgroupid) filtertxt += "分单类别:" + this.getOptionName(this.reqgroupOption.filter((item) => ("," + this.reqgroupid + ",").indexOf("," + item.data + ",") > -1)) + "; ";
            if (this.groupcombid) filtertxt += "分单类别组合:" + (this.groupcombname ? this.groupcombname : this.groupcombid) + "; ";
            if (this.emerflag == "1") filtertxt += "仅显示急诊标本; ";
            if (this.sendflag == "1") filtertxt += "仅显示已送达标本; ";
            if (this.islisreqbarcode == "1") filtertxt += "剔除实验室手工添条码; ";
            if (this.onlyreportvsreqdetail == "1") filtertxt += "仅显示申请项目部分上机的; ";
            if (this.isrejectonlinebarcode == "1") filtertxt += "剔除已上机状态条码; ";
            //这边防止版本更新后条件未切换直接使用更新前的本地缓存，然后缓存中取不到名称导致条件无法正常显示
            if (this.performdept) filtertxt += "执行科室:" + (this.performdeptname ? this.performdeptname : this.performdept) + "; ";
            if (this.labdeptcode) filtertxt += "检验科室:" + (this.labdeptname ? this.labdeptname : this.labdeptcode) + "; ";
            if (this.reqitem) filtertxt += "申请项目:" + this.getOptionName(this.reqitemOption.filter((item) => ("," + this.reqitem + ",").indexOf("," + item.data + ",") > -1)) + "; ";
            if (this.rptunitid) filtertxt += "报告单元:" + this.getOptionName(this.rptunitOption.filter((item) => ("," + this.rptunitid + ",").indexOf("," + item.data + ",") > -1)) + "; ";
            if (this.specimencode) filtertxt += "标本类型:" + (this.specimenname ? this.specimenname : this.specimencode) + "; ";
            if (this.recieveuser) filtertxt += "签收人:" + (this.recieveusername ? this.recieveusername : this.recieveuser) + "; ";
            if (this.reqcombid) filtertxt += "申请项目组合:" + (this.reqcombname ? this.reqcombname : this.reqcombid) + "; ";
            if (this.recgroupid) filtertxt += "签收工作组:" + (this.recgroupname ? this.recgroupname : this.recgroupid) + "; ";
            if (this.labhospital) filtertxt += "检验医院:" + (this.labhospname ? this.labhospname : this.labhospital) + "; ";
            if (this.txtbarcode) filtertxt += "条码号:" + this.txtbarcode + "; ";
            return filtertxt;
        },
        getOptionName(option) {
            if (option && option.length > 0) {
                let optionname = "";
                option.forEach((item) => {
                    if (item.hasOwnProperty("display")) {
                        optionname += item.display + ",";
                    } else {
                        optionname += item.label + ",";
                    }
                });
                return optionname.substring(0, optionname.length - 1);
            } else {
                return "";
            }
        },
        getExportData(columns) {
            let datas = this.sampleData;
            let headers = [columns.map((item) => item.title)];
            return headers.concat(
                datas.map((row) => {
                    return columns.map((column) => {
                        switch (column.property) {
                            case "emer_flag":
                                return row[column.property] == "1" ? "急" : "";
                            case "pat_sex":
                                if (!row[column.property]) {
                                    return "";
                                } else {
                                    return row[column.property] == "1" ? "男" : "女";
                                }
                            default:
                                return row[column.property];
                        }
                    });
                })
            );
        },
        ReqItemRowName({ row, rowIndex }) {
            if (!row.reportid) {
                return "rm_cell_yellow";
            }
        },
        hideinstalledChange(val) {
            this.hideinstalled = val;
            localStorage.setItem("lis240hideinstalled", this.hideinstalled);
            this.QueryReq(this.selrow.barcode);
        },
        haveChange(type) {
            switch (type) {
                case 1:
                    localStorage.setItem("lis240pattype", this.pattype);
                    break;
                case 2:
                    localStorage.setItem("lis240statflag", this.statflag);
                    break;
                case 3:
                    localStorage.setItem("lis240workgroupreeieveflag", this.workgroupreeieveflag);
                    break;
                case 4:
                    localStorage.setItem("lis240reqflag", this.reqflag);
                    break;
                case 5:
                    localStorage.setItem("lis240labgroup", this.labgroup);
                    break;
                case 6:
                    localStorage.setItem("lis240reqgroupid", this.reqgroupid);
                    break;
                case 7:
                    localStorage.setItem("lis240dept", this.performdept);
                    localStorage.setItem("lis240deptname", this.performdeptname);
                    break;
                case 8:
                    localStorage.setItem("lis240labdept", this.labdeptcode);
                    localStorage.setItem("lis240labdeptname", this.labdeptname);
                    break;
                case 9:
                    localStorage.setItem("lis240reqitem", this.reqitem);
                    break;
                case 10:
                    localStorage.setItem("lis240rptunitid", this.rptunitid);
                    break;
                case 11:
                    localStorage.setItem("lis240specimencode", this.specimencode);
                    localStorage.setItem("lis240specimenname", this.specimenname);
                    break;
                case 12:
                    localStorage.setItem("lis240recieveuser", this.recieveuser);
                    localStorage.setItem("lis240recieveusername", this.recieveusername);
                    break;
                case 13:
                    localStorage.setItem("lis240reqcombid", this.reqcombid);
                    localStorage.setItem("lis240reqcombname", this.reqcombname);
                    break;
                case 14:
                    localStorage.setItem("lis240recgroupid", this.recgroupid);
                    localStorage.setItem("lis240recgroupname", this.recgroupname);
                    break;
                case 15:
                    localStorage.setItem("lis240labhospital", this.labhospital);
                    localStorage.setItem("lis240labhospname", this.labhospname);
                    break;
                case 16:
                    localStorage.setItem("lis240groupcombid", this.groupcombid);
                    localStorage.setItem("lis240groupcombname", this.groupcombname);
                    break;
                case 17:
                    localStorage.setItem("lis240emerflag", this.emerflag);
                    break;
                case 18:
                    localStorage.setItem("lis240sendflag", this.sendflag);
                    break;
                case 19:
                    localStorage.setItem("lis240islisreqbarcode", this.islisreqbarcode);
                    break;
                case 20:
                    localStorage.setItem("lis240onlyreportvsreqdetail", this.onlyreportvsreqdetail);
                    break;
                case 21:
                    localStorage.setItem("lis240isrejectonlinebarcode", this.isrejectonlinebarcode);
                    break;

                default:
                    break;
            }
        },
        repalceComputerName(row) {
            this.$pub
                .getComputerName(row.mac_address)
                .then((name) => {
                    row.computer_name = name;
                })
                .catch(() => {
                    this.$message.error("机器名称查询失败！");
                    //保持原样
                });
        },
        showhelp(t) {
            this.$pub.showhelp(this, t);
        },
    },
};
</script>

<style scoped>
table tr td:nth-child(odd) {
    text-align: right;
    white-space: nowrap;
}
table tr td:nth-child(even) {
    text-align: left;
}
table {
    font-size: 12px;
    border-collapse: separate;
    border-spacing: 5px;
}
.middle-tab-top {
    position: absolute;
    top: 0px;
    width: 100%;
    height: 200px;
}
.middle-bottom {
    position: absolute;
    top: 37px;
    width: 100%;
    bottom: 0px;
    overflow: auto;
}
.middle-tab-bottom {
    position: absolute;
    top: 203px;
    width: 100%;
    bottom: 0px;
    overflow: auto;
}
.pagetop {
    left: 0;
    right: 0;
    height: 215px;
    display: -webkit-box;
    -webkit-box-pack: center;
    -webkit-box-align: center;
    border: solid 1px #ccc;
    position: absolute;
    z-index: 99;
    overflow-x: auto;
    white-space: nowrap;
}
.pagebottom {
    position: absolute;
    width: 100%;
    left: 0;
    margin-top: 4px;
    height: 36px;
    bottom: 0px;
    -webkit-box-pack: center;
    -webkit-box-align: center;
    border: solid 1px #ccc;
}
.middle-right {
    position: absolute;
    top: 0;
    bottom: 0px;
    overflow: visible;
    width: 100%;
    right: 0px;
}

.right-inser {
    position: absolute;
    top: 0;
    bottom: 0px;
    overflow: visible;
    width: 100%;
    right: 0px;
}
.middle-right {
    position: absolute;
    top: 0;
    bottom: 0px;
    overflow: visible;
    width: 100%;
    right: 0px;
}

.right-inser {
    position: absolute;
    top: 0;
    bottom: 0px;
    overflow: visible;
    width: 100%;
    right: 0px;
}

.table-bottom {
    font-size:12px;
    padding-right: 30px;
    padding-bottom: 10px;
    text-align:right;
}
</style>